package controler.edition;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.SystemColor;
import java.util.ArrayList;
import java.util.List;

import javax.swing.BoxLayout;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListModel;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;

import model.dao.NewsDAO;
import controler.News;

public class EditNews {
	
	public void ajouterNews(String libelle, String description, String lien, String type) {
		News news = new News();
		news.setLibelle(libelle);
		news.setDescription(description);
		news.setLien(lien);
		news.setType(type);
		new NewsDAO(news).ajouter();
	}
	
	public DefaultListModel listerAll() {
		List<News> listNews = NewsDAO.selectAll(0);
		DefaultListModel model = new DefaultListModel<>();
		
		for (News news : listNews) {
			String line = news.getId() + " | ";
			line += news.getLibelle() + " | ";
			line += news.getLien() + " | ";
			line += news.getType();
			model.addElement(line);
		}
		return model;
	}
	
	public News recupNews(int id) {
		NewsDAO dao = new NewsDAO(new News(id));
		dao.recupInfos();
		return dao.getNews();
	}
	
	public void delete(int id) {
		NewsDAO dao = new NewsDAO(new News(id));
		dao.supprimer();
	}

	public void update(int id, String libelle, String description, String lien, String type) {
		News news = new News(id);
		news.setLibelle(libelle);
		news.setDescription(description);
		news.setLien(lien);
		news.setType(type);
		new NewsDAO(news).modifier();
	}
}


